package com.example.demo2;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.lang.Object;

import java.sql.BatchUpdateException;
import java.util.ArrayList;

public class drMainActivity extends AppCompatActivity {

    private EditText edit1,edit2;
    private Button but1;
    private TextView ttttt1;

//    Bundle bundle = new Bundle();
//    ArrayList list = bundle.getParcelableArrayList("List1");
//    ArrayList list2 = new ArrayList();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dr_main);

        but1 = (Button)findViewById(R.id.but2);
        edit1=(EditText)findViewById(R.id.editdr);
        edit2=(EditText)findViewById(R.id.editdrr);
        ttttt1 = (TextView)findViewById(R.id.ttttt1) ;


        //ArrayList list = bundle.getParcelableArrayList("List");

//        Bundle bundleObject = getIntent().getExtras();
//        // Get ArrayList Bundle
//        final ArrayList<username> userArrayList = (ArrayList<username>) bundleObject.getSerializable("key");
//        for (int j=0;j<userArrayList.size();j++){
//            username urr = userArrayList.get(j);
//            ttttt1.setText(urr.getId()+urr.getName()+urr.getPassword());
//
//        }
        but1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int i;
                Bundle bundle = getIntent().getExtras();
                ArrayList<username> userArrayList = (ArrayList<username>) bundle.getSerializable("key");
                //ArrayList<username> userArrayList = (ArrayList<username>) bundle.getSerializable("key");
//                for (int j=0;j<userArrayList.size();j++){
//                    username urr = userArrayList.get(j);
//                    ttttt1.setText(urr.getId()+urr.getName()+urr.getPassword());
//                 }
                for (i=0;i<userArrayList.size();i++){
                    username uid = userArrayList.get(i);
                    if(edit1.getText().toString().equals(uid.getId())){
                        if(edit2.getText().toString().equals(uid.getPassword())){
                            Intent intent = new Intent(drMainActivity.this,fwMainActivity.class);
                            intent.putExtras(bundle);
                            startActivityForResult(intent,1);
                            break;
                        }
                        else{
                            Toast.makeText(drMainActivity.this, "密码错误", Toast.LENGTH_SHORT).show();
                            break;
                        }
                    }
                }
                if(i==userArrayList.size()){
                    Toast.makeText(drMainActivity.this, "账号不存在", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
